home *** CD-ROM | disk | FTP | other *** search
- {----------------------------------------------------------------------------
- |
- | Library: Spider Containers for Object Pascal
- |
- | Module: StkTest.Pas
- |
- | Description: Form for TStack test.
- |
- | History: Version 1.0 March 1996. Copyright (c) 1996 Michel Brazeau
- | Interval Software
- |
- |---------------------------------------------------------------------------}
- unit StkTest;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls,
-
- ObjStack; { TStack }
-
- type
- TStackForm = class(TForm)
- PushButton: TButton;
- PopButton: TButton;
- ClearButton: TButton;
- ItemCount: TLabel;
- ListBox: TListBox;
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure PushButtonClick(Sender: TObject);
- procedure PopButtonClick(Sender: TObject);
- procedure ClearButtonClick(Sender: TObject);
- private
- { Private declarations }
- Stack : TStack;
-
- { redraws the list box, from the contents of the stack }
- procedure UpdateListBox;
-
- { iterator method to add a TStringCombo to the list box }
- procedure AddString(const Obj : TObject);
-
- public
- { Public declarations }
- end;
-
- {--------------------------------------------------------------------------}
-
- implementation
-
- {$R *.DFM}
-
- uses
- ObjBuckt; { TStringCombo }
-
- {--------------------------------------------------------------------------}
-
- procedure TStackForm.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- Action := caFree;
- end;
-
- {--------------------------------------------------------------------------}
-
- procedure TStackForm.FormCreate(Sender: TObject);
- begin
- Stack := TStack.Create(TStringCombo);
- end;
-
- {--------------------------------------------------------------------------}
-
- procedure TStackForm.FormDestroy(Sender: TObject);
- begin
- Stack.Free;
- end;
-
- {--------------------------------------------------------------------------}
-
- procedure TStackForm.UpdateListBox;
- begin
- ListBox.Clear;
-
- Screen.Cursor := crHourGlass;
-
- ListBox.Enabled := False;
-
- try
-
- Stack.ForEachCallMethod(AddString);
-
- finally
-
- ListBox.Enabled := True;
- Screen.Cursor := crDefault;
-
- end;
-
- ItemCount.Caption := IntToStr(Stack.Size);
- end;
-
- {--------------------------------------------------------------------------}
-
- procedure TStackForm.AddString(const Obj : TObject);
- begin
- ListBox.Items.Add((Obj as TStringCombo).Str);
- end;
-
- {--------------------------------------------------------------------------}
-
- procedure TStackForm.PushButtonClick(Sender: TObject);
- const
- Str : String = '';
-
- var
- StringCombo : TStringCombo;
-
- begin
- if not InputQuery('', 'String to push: ', Str) then
- Exit;
-
- StringCombo := TStringCombo.Create(Str, nil);
- try
- Stack.Push(StringCombo);
- except
- StringCombo.Free;
- end;
-
- UpdateListBox;
- end;
-
- {--------------------------------------------------------------------------}
-
- procedure TStackForm.PopButtonClick(Sender: TObject);
- var
- StringCombo : TStringCombo;
-
- begin
- StringCombo := Stack.Pop as TStringCombo;
-
- MessageDlg(StringCombo.Str + ' popped.', mtInformation, [mbOk], 0);
-
- StringCombo.Free;
-
- UpdateListBox;
- end;
-
- {--------------------------------------------------------------------------}
-
- procedure TStackForm.ClearButtonClick(Sender: TObject);
- begin
- Stack.Clear;
-
- UpdateListBox;
- end;
-
- {--------------------------------------------------------------------------}
-
- end.
-